package leetcode.秋招.网易;

/**
 * @author ：zsy
 * @date ：Created 2021/8/21 15:07
 * @description：
 */
public class Main2 {

    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.findKthBit(4, 11));
    }

}
class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * 返回Sn的第k位字符
     * @param n int整型 Sn的n
     * @param k int整型 需要返回的字符下标位
     * @return char字符型
     */
    public char findKthBit (int n, int k) {
        // write code here
        String S = "a";
        char L = 'a';
        for (int i = 1; i < n; i++) {
            char curL = (char) ((int)L + i);
            String invertS = reverse(S);
            String curS = S + curL + invertS;
            S = curS;
        }
        return S.charAt(k - 1);
    }

    private String reverse(String s) {
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            builder.append((char) ('z' - s.charAt(i) + 'a'));
        }
        return builder.reverse().toString();
    }
}
